const mysql = require('mysql');
const connection = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: 'wenjinbao',
    database: 'bao'
});

connection.connect(function(err) {
    if (err) {
        console.error('error connecting: ' + err.stack);
        return;
    }
    console.log('db connection successful!');
});
const query = (sql) => {
    return new Promise((resovle, reject) => {
        connection.query(sql, function(error, results) {
            if (error) {
                reject(error)
            } else {
                resovle(results)
            }
        });
    })
}
module.exports = query;